package com.alks.function.controller.administration;

import com.alks.common.aop.ApiRestController;
import com.alks.common.aop.WebLogger;
import com.alks.entity.data.response.ResponseInfo;
import com.alks.function.config.ProfileConfig;
import com.alks.function.data.request.administration.AttendanceDetailsRequest;
import com.alks.function.data.request.administration.PcEmpAttendUpdateRequest;
import com.alks.function.service.administration.PcEmpAttendService;
import com.alks.function.service.finance.attend.AttendanceCalculateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;


@ApiRestController("/emp")
@Api(tags = {"行政人事-人事作业模块-考勤资料作业","行政人事-人事查询模块-考勤资料查询"})
@Slf4j
public class PcEmpAttendController {

    @Autowired
    private PcEmpAttendService pcEmpAttendService;
    @Resource
    private AttendanceCalculateService attendanceCalculateService;
    @Resource
    private ProfileConfig profileConfig;

    @WebLogger
    @ApiOperation(value = "考勤明细",tags = "行政人事-人事查询模块-考勤资料查询")
    @PostMapping("/getAll")
    public ResponseInfo getAll(@RequestBody AttendanceDetailsRequest request){
        return pcEmpAttendService.getAttendanceDetails(request);

    }

    @WebLogger
    @ApiOperation(value = "查询",tags = "行政人事-人事作业模块-考勤资料作业")
    @PostMapping("/AttendanceDataQuery")
    public ResponseInfo AttendanceDataQuery(@RequestBody AttendanceDetailsRequest request){
        return pcEmpAttendService.AttendanceDataQuery(request);
    }

    @WebLogger
    @ApiOperation(value = "考勤公休日定义查询",tags = "行政人事-人事作业模块-考勤资料作业")
    @PostMapping("/AttendancePublicHolidays")
    public ResponseInfo AttendancePublicHolidays(@RequestParam(required = false) String years){
        return pcEmpAttendService.AttendancePublicHolidays(years);
    }

    @WebLogger
    @ApiOperation(value = "考勤公休日定义查询",tags = "行政人事-人事作业模块-考勤资料作业")
    @PostMapping("/AttendancePublicHolidaysV2")
    public ResponseInfo attendancePublicHolidaysV2(@RequestParam(required = false) String years){
        return pcEmpAttendService.attendancePublicHolidaysV2(years);
    }

    @WebLogger
    @ApiOperation(value = "修改",tags = "行政人事-人事作业模块-考勤资料作业")
    @PostMapping("/AttendanceDataUpdate")
    public ResponseInfo AttendanceDataUpdate(@RequestBody PcEmpAttendUpdateRequest request){
        return pcEmpAttendService.AttendanceDataUpdate(request);
    }

    @WebLogger
    @ApiOperation(value = "删除",tags = "行政人事-人事作业模块-考勤资料作业")
    @PostMapping("/AttendanceDataDel")
    public ResponseInfo AttendanceDataDel(@RequestBody PcEmpAttendUpdateRequest request){
        return pcEmpAttendService.AttendanceDataDel(request);
    }

    @WebLogger
    @ApiOperation(value = "插入当月周末日期",tags = "行政人事-人事作业模块-考勤资料作业")
    @PostMapping("/InsertTheWeekendDateOfTheCurrentMonth")
    public ResponseInfo InsertTheWeekendDateOfTheCurrentMonth(@RequestParam(required = false) String years){
        return pcEmpAttendService.InsertTheWeekendDateOfTheCurrentMonth(years);
    }

    @WebLogger
    @ApiOperation(value = "考勤公休定义删除",tags = "行政人事-人事作业模块-考勤资料作业")
    @PostMapping("/psHoliday2Del")
    public ResponseInfo psHoliday2Del(@RequestParam String years){
        return pcEmpAttendService.psHoliday2Del(years);
    }
    @WebLogger
    @ApiOperation(value = "考勤公休定义添加",tags = "行政人事-人事作业模块-考勤资料作业")
    @PostMapping("/psHoliday2Add")
    public ResponseInfo psHoliday2Add(@RequestParam String years, @RequestParam(required = false) Integer legalHoliday){
        return pcEmpAttendService.psHoliday2Add(years, legalHoliday);
    }


    @WebLogger
    @ApiOperation(value = "考勤公休定义修改",tags = "行政人事-人事作业模块-考勤资料作业")
    @PostMapping("/psHoliday2Update")
    public ResponseInfo psHoliday2Update(@RequestParam@ApiParam("公休日期") String years, @RequestParam@ApiParam("新公休日期") String newYears,
                                         @RequestParam(required = false) Integer legalHoliday){
        return pcEmpAttendService.psHoliday2Update(years,newYears, legalHoliday);
    }

    @WebLogger
    @PostMapping("/ImportAttendanceData")
    @ApiOperation(value = "导入考勤资料",tags = "行政人事-人事作业模块-考勤资料作业")
    public ResponseInfo ImportAttendanceData(@RequestParam MultipartFile file){
        return pcEmpAttendService.ImportAttendanceData(file);
    }

    @WebLogger
    @PostMapping("/isVNMProfile")
    @ApiOperation(value = "是否是越南环境",tags = "行政人事-人事作业模块-考勤资料作业")
    public ResponseInfo isVNMProfile(){
        return ResponseInfo.ok(profileConfig.isVNMProfile());
    }

    @WebLogger
    @PostMapping("/syncVNMAttendData")
    @ApiOperation(value = "同步越南考勤资料",tags = "行政人事-人事作业模块-考勤资料作业")
    public ResponseInfo syncVNMAttendData(@RequestParam String beginDate, @RequestParam String endDate){
        return ResponseInfo.ok(attendanceCalculateService.syncAttendData(beginDate, endDate));
    }

    @WebLogger
    @ApiOperation(value = "导出考勤报表",tags = "行政人事-人事查询模块-考勤资料查询")
    @GetMapping("/ExportAttendanceReport")
    public void ExportAttendanceReport(@RequestParam(required = false) String years, HttpServletResponse response){
         pcEmpAttendService.ExportAttendanceReport(years,response);
    }
}
